We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392626 - %rep listing line numbering should reset after every iteration
Summary: %rep listing line numbering should reset after every iteration
Status: CLOSED FIXED
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 2.15.xx
Hardware: All All
: Medium minor
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2019-10-24 06:19 PDT by E. C. Masloch
Modified: 2020-05-06 16:03 PDT (History)
4 users (show)

Obtained from: Built from git using configure
Generated by: ---
Bug category:
Observed for: ---
Regression: ---
Regression since:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2019-10-24 06:19:17 PDT
This is with https://repo.or.cz/nasm.git/commitdiff/e91f5cc1322eed4da0de81656276e021bf352c3d


$ cat test.asm
		; line 1
%rep 3		; line 2
		; line 3
	db 26h	; line 4
%endrep		; line 5
		; line 6
$ nasm -v
NASM version 2.15rc0 compiled on Oct 24 2019
$ nasm test.asm -l test.lst
$ cat test.lst
     1                                  		; line 1
     2                                  %rep 3		; line 2
     3                                  		; line 3
     4                                  	db 26h	; line 4
     5                                  %endrep		; line 5
     3                              <1> 
     4 00000000 26                  <1>  db 26h
     5                              <1> 
     6 00000001 26                  <1>  db 26h
     7                              <1> 
     8 00000002 26                  <1>  db 26h
     6                                  		; line 6
$ 


Note how the first iteration's db is listed as line 4 (matching the true source line from where the %rep content is defined), but the subsequent iterations list db as line 6 and 8 respectively. After the %rep is done processing, the line number correctly resets to 6.

In older NASM, the line number stays at that of the %endrep line:


$ oldnasm -v
NASM version 2.12.02 compiled on Aug 10 2019
$ oldnasm test.asm -l test.lst
$ cat test.lst
     1                                  		; line 1
     2                                  %rep 3		; line 2
     3                                  		; line 3
     4                                  	db 26h	; line 4
     5                                  %endrep		; line 5
     5                              <1> 
     5 00000000 26                  <1>  db 26h
     5                              <1> 
     5 00000001 26                  <1>  db 26h
     5                              <1> 
     5 00000002 26                  <1>  db 26h
     6                                  		; line 6
$
Comment 1 Chang S. Bae 2020-02-07 14:08:32 PST
For the record, found this commit for causing this regression:

commit ab6f8319552f17d269a5bf2facea48ea1c338b71 ab6f8319
Author: H. Peter Anvin <hpa@zytor.com>
Date:   Fri Aug 9 22:31:45 2019 -0700

    listing: when listing lines in macros and rep blocks, show the actual line
    
    When printing lines coming from %rep blocks and macros, show the line
    number corresponding to the line actually being printed.
    
    Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Comment 2 Chang S. Bae 2020-02-07 16:01:04 PST
(In reply to Chang S. Bae from comment #1)

> For the record, found this commit for causing this regression:
> 
> commit ab6f8319552f17d269a5bf2facea48ea1c338b71 ab6f8319
> Author: H. Peter Anvin <hpa@zytor.com>
> Date:   Fri Aug 9 22:31:45 2019 -0700
> 
>     listing: when listing lines in macros and rep blocks, show the actual
> line
>     
>     When printing lines coming from %rep blocks and macros, show the line
>     number corresponding to the line actually being printed.
>     
>     Signed-off-by: H. Peter Anvin <hpa@zytor.com>

This commit seems to be missing to reset the original line number in each iteration for processing %rep. A quick fix like this seems to be working:

diff --git a/asm/preproc.c b/asm/preproc.c
index 63e5f649..583925d4 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -6179,6 +6179,7 @@ static Token *pp_tokline(void)
                    Token *t, *tt, **tail;
                     Line *ll;
 
+                    istk->mstk.mstk->lineno = 0;
                     nasm_new(ll);
                     ll->next = istk->expansion;
                     tail = &ll->first;
Comment 3 Chang S. Bae 2020-05-06 16:03:23 PDT
This commit should have resolved the issue:


commit	bec812fc4b56d0ff8c2321f8ac47ffe41e86e9ca
author	Chang S. Bae <chang.seok.bae@intel.com>	
Fri, 7 Feb 2020 23:49:38 +0000 (7 15:49 -0800)
committer	Chang S. Bae <chang.seok.bae@intel.com>	
Fri, 17 Apr 2020 21:33:33 +0000 (17 21:33 +0000)
preproc: Fix to reset %rep list line number after every iteration

The code has been fixed to print the corresponding line
numbers of %rep blocks correctly, but only for the first
iteration. For the subsequent iterations, the current line
number on the expansion needs to be explicitly reset again.

Fixes: ab6f8319552f ("listing: when listing lines in macros
and rep blocks, show the actual line")